/*
package com.ww.springboot.pdf;

import com.spire.barcode.BarcodeScanner;
import com.ww.springboot.boot.utils.ObjectUtil;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.pdfbox.text.PDFTextStripperByArea;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class PdfUtil {

    private static Tesseract tesseract = new Tesseract();

    static {
        //tesseract.setLanguage("eng"); // 默认就是eng，你可以选择其他lang
        tesseract.setDatapath("C:\\Program Files\\tessdata2\\");
    }

    */
/**
 * pdf 转 图片
 *
 * @param bytes
 * @return
 * @throws Exception
 * <p>
 * 从pdf中读条形码
 * @param bytes
 * @return 从pdf中读文字
 * @param bytes
 * @return 读图片
 * @param bytes
 * @return
 *//*

    public static byte[] pdfToImageFile(byte[] bytes) {
        PDDocument doc = null;
        ByteArrayOutputStream os = null;
        InputStream stream = null;
        ByteArrayOutputStream out = null;
        try {
            // pdf路径
            stream = new ByteArrayInputStream(bytes);
            // 加载解析PDF文件
            doc = PDDocument.load(stream);
            PDFRenderer pdfRenderer = new PDFRenderer(doc);
//            PDPageTree pages = doc.getPages();
//            int pageCount = pages.getCount();
            BufferedImage bim = pdfRenderer.renderImageWithDPI(0, 200);
            os = new ByteArrayOutputStream();
            ImageIO.write(bim, "jpg", os);
            return os.toByteArray();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        } finally {
            try {
                if (doc != null) doc.close();
                if (os != null) os.close();
                if (stream != null) stream.close();
                if (out != null) out.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    */
/**
 * 从pdf中读条形码
 *
 * @param bytes
 * @return
 *//*

    public static List<String> readBarcodeByStream(byte[] bytes) {
        try (InputStream inputStream = new ByteArrayInputStream(pdfToImageFile(bytes))) {
            String[] array = BarcodeScanner.scan(inputStream);
            return Arrays.asList(array);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    */
/**
 * 从pdf中读文字
 *
 * @param bytes
 * @return
 *//*

    public static List<String> readTextByPdf(byte[] bytes) {
        List<String> list = new ArrayList<>();

        try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
             PDDocument document = PDDocument.load(inputStream)) {
            document.getClass();

            if (!document.isEncrypted()) {

                PDFTextStripperByArea stripper = new PDFTextStripperByArea();

                stripper.setSortByPosition(true);

                PDFTextStripper tStripper = new PDFTextStripper();

                String pdfFileInText = tStripper.getText(document);

                String lines[] = pdfFileInText.split("\\r?\\n");

                for (String line : lines) {
                    line = line.replace(" ", "");
                    list.add(line);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    */
/**
 * 读图片
 *
 * @param bytes
 * @return
 *//*

    public static List<String> readTextByPic(byte[] bytes, String type) throws IOException, TesseractException {
        BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes));
        tesseract.setLanguage(ObjectUtil.isNotEmpty(type) ? type : "eng");
        String ocr = tesseract.doOCR(image);
        String[] split = ocr.split("\n");
        List<String> collect2 = Arrays.stream(split).map(sss -> sss = sss.replace(" ", "")).collect(Collectors.toList());
        return collect2;
    }
}
*/
